from selenium.webdriver import ActionChains
from hyrobot.common import *
import pyautogui
import pytest
import time
import json
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from lib.webui_local_mysql import *

class c73258:
    # name = '产品管理员能查看所有自己创建的产品-c73258'  # 测试用例名字

    cases = [
        ('1c73258','zhangsan','123456','张三'),
        ('2c73258','lijunyi','123456','李俊沂'),
        ('3c73258','zhang25','123456','张25'),
        ('4c73258','zhang32', '123456', '张32'),
    ]

    def setup(self):
        STEP(1, '登陆网站')
        wd = open_browser()

    # 清除方法
    def teardown(self):
        wd = get_global_webdriver()
        wd.quit()
    # 测试用例步骤
    def teststeps(self, para_index):
        # 取出参数
        username, password = self.cases[para_index][1:3]
        # 下面写登录流程
        driver = get_global_webdriver()
        driver.get("http://172.17.66.19:8080/")


        driver.find_element(By.NAME, "username").send_keys(username)
        driver.find_element(By.NAME, "password").send_keys(password)
        driver.find_element(By.CSS_SELECTOR, ".el-button").click()
        time.sleep(2)
        extending_button = driver.find_element_by_id("hamburger-container")
        try:
            driver.find_element(By.CLASS_NAME, "el-tooltip")
            extending_button.click()
        except:
            print("左侧栏没有隐藏")
        # click product manage
        time.sleep(1)
        product_manage_word2 = driver.find_element(By.XPATH,
                                                   "/html/body/div/div/div[1]/ul/div[3]/a/li/span"
                                                   )
        product_manage_word2.click()
        time.sleep(1)
        top_title2 = driver.find_element(By.XPATH,
                                         "/html/body/div/div/div[2]/div/div/div[2]/span/span[2]/span[1]/span"
                                         ).text
        CHECK_POINT("上方第3个标题对应", "产品管理" == top_title2)

        STEP(2, "确认在产品管理界面所有可见的产品均是此账户创建")
        uploader_list = get_colum_list(driver,2)
        expect_uploader = self.cases[para_index][3]
        times = 1
        for i in uploader_list:
            INFO(i)
            INFO(times)
            CHECK_POINT("验证上传人是否一致",i == expect_uploader)
            times += 1

        # driver.quit()